/*
 * BrokenStep.cpp
 *
 *  Created on: Dec 14, 2011
 *      Author: jianli
 */

#include "UnregularSprite.h"

void UnregularSprite::update(Uint32 ticks) {
	if (collided) {
		Y(Y() + (float) ticks * 0.001 * velocityY());
		advanceFrame(ticks);
	}
}

bool UnregularSprite::collide(Sprite* s)
{
	if(!collided) {
		collided = true;
		velocityY(100.0);
	}
	return false;
}

void UnregularSprite::draw() const
{
	MultiSprite::draw();
}

const Frame *UnregularSprite::getFrame() const
{
	return MultiSprite::getFrame();
}

void UnregularSprite::advanceFrame(Uint32 ticks) {
	static float ms = 1000.0 / frameInterval;
	static float dt = 0;
	dt += ticks;
	int df = dt / ms;
	dt -= df * ms;

	if (currentFrame <= numberOfFrames - 1) {
		currentFrame = (currentFrame + df);
		if (currentFrame >= numberOfFrames)
				currentFrame = numberOfFrames - 1;
	}
}
